Don't run cargo as root during `make install`
authorAlex Crichton <alex@alexcrichton.com>
Sun, 7 Sep 2014 18:26:07 +0000 (11:26 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Sun, 7 Sep 2014 18:26:07 +0000 (11:26 -0700)
This rejiggers the dependencies for `make install` to only copy files into the
destination, never assemble anything. This adds a hard requirement that `make`
is executed before `make install`.

Closes #519

Makefile.in
src/etc/install.sh

index b1303b1a591b44df5a4d0e8f58e5b705a079790a..47f7656fc0ffef7997dab275204d20274d75e446 100644 (file)
@@ -115,7 +115,9 @@ distcheck-$(1): dist-$(1)
 $$(DISTDIR_$(1))/$$(PKG_NAME)-$(1).tar.gz: $$(PKGDIR_$(1))/lib/cargo/manifest.in
        tar -czvf $$@ -C $$(@D) $$(PKG_NAME)-$(1)
 
-$$(PKGDIR_$(1))/lib/cargo/manifest.in: all
+$$(PKGDIR_$(1))/lib/cargo/manifest.in:
+       @[ -f $$(TARGET_$(1))/cargo$$(X) ] || echo 'Please run `make` first'
+       @[ -f $$(TARGET_$(1))/cargo$$(X) ]
        rm -rf $$(PKGDIR_$(1))
        mkdir -p $$(PKGDIR_$(1))/bin $$(PKGDIR_$(1))/lib/cargo
        cp $$(TARGET_$(1))/cargo$$(X) $$(PKGDIR_$(1))/bin
@@ -128,16 +130,23 @@ $$(PKGDIR_$(1))/lib/cargo/manifest.in: all
        mv $$(DISTDIR_$(1))/manifest-$$(PKG_NAME).in \
                $$(PKGDIR_$(1))/lib/cargo/manifest.in
 
-install-$(1): $$(PKGDIR_$(1))/lib/cargo/manifest.in
+ifeq (root user, $$(USER) $$(patsubst %,user,$$(SUDO_USER)))
+prepare-manifest-$(1):
+       @sudo -u "$$$$SUDO_USER" $$(MAKE) prepare-manifest-$(1)
+else
+prepare-manifest-$(1): $$(PKGDIR_$(1))/lib/cargo/manifest.in
+endif
+
+install-$(1): prepare-manifest-$(1)
        $$(PKGDIR_$(1))/install.sh \
                --prefix="$$(CFG_PREFIX)" \
                --destdir="$$(DESTDIR)/" $$(MAYBE_DISABLE_VERIFY)
 endef
 $(foreach target,$(CFG_TARGET),$(eval $(call DO_DIST_TARGET,$(target))))
 
-dist: $(CARGO) $(foreach target,$(CFG_TARGET),dist-$(target))
-distcheck: $(CARGO) $(foreach target,$(CFG_TARGET),distcheck-$(target))
-install: $(CARGO) $(foreach target,$(CFG_TARGET),install-$(target))
+dist: $(foreach target,$(CFG_TARGET),dist-$(target))
+distcheck: $(foreach target,$(CFG_TARGET),distcheck-$(target))
+install: $(foreach target,$(CFG_TARGET),install-$(target))
 
 # Setup phony tasks
 .PHONY: all clean test test-unit style
index 5eeb316f950585fadcb261e446d35c5d7b735ad1..5d913c75a6cfbcd12e294e09d03b33d80a708bd3 100755 (executable)
@@ -305,7 +305,7 @@ then
     if [ -z "${CFG_UNINSTALL}" ]
     then
         msg "verifying platform can run binaries"
-        "${CFG_SRC_DIR}/bin/cargo" -V > /dev/null
+        "${CFG_SRC_DIR}/bin/cargo" -V 2> /dev/null
         if [ $? -ne 0 ]
         then
             err "can't execute rustc binary on this platform"
@@ -448,7 +448,7 @@ done < "${CFG_SRC_DIR}/${CFG_LIBDIR_RELATIVE}/cargo/manifest.in"
 if [ -z "${CFG_DISABLE_VERIFY}" ]
 then
     msg "verifying installed binaries are executable"
-    "${CFG_DESTDIR}${CFG_PREFIX}/bin/cargo" -V > /dev/null
+    "${CFG_DESTDIR}${CFG_PREFIX}/bin/cargo" -V 2> /dev/null
     if [ $? -ne 0 ]
     then
         ERR="can't execute installed rustc binary. "